package com.terrorism.first.adapter;

import java.util.List;

import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.terrorism.first.R;
import com.terrorism.first.model.HotOfCategoryModel;
import com.terrorism.sdk.photo.PhotoLoader;
import com.terrorism.sdk.utils.PhotoUtils;

public class HotOfCategoryAdapter extends BaseAdapter {

	List<HotOfCategoryModel> listData;
	Context mContext;
	LayoutInflater inflater;
	int withOfImage;
//	Activity rootActivity;
	
	public int getWithOfImage() {
		return withOfImage;
	}
	public void setWithOfImage(int withOfImage) {
		this.withOfImage = withOfImage;
	}
	public HotOfCategoryAdapter()
	{
		super();
	}
	public HotOfCategoryAdapter(List<HotOfCategoryModel> data,Context context)
	{
		super();
		listData = data;
		mContext = context;
		inflater =(LayoutInflater) mContext.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
	}
	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return listData.size();
	}

	@Override
	public Object getItem(int arg0) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public long getItemId(int arg0) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup arg2) {
		// TODO Auto-generated method stub
		HotOfCategoryModel data = listData.get(position);
		MyHolder holder = new MyHolder();
		if(convertView==null)
		{
			convertView = inflater.inflate(R.layout.item_hot_of_category, arg2, false);
			holder.tvRank1Name = (TextView) convertView.findViewById(R.id.tvRank1Name);
			holder.tvRank2Name = (TextView) convertView.findViewById(R.id.tvRank2Name);
			holder.tvRank3Name = (TextView) convertView.findViewById(R.id.tvRank3Name);
			holder.tvCategoryName = (TextView) convertView.findViewById(R.id.tvHotCategoryName);
			holder.imgRank1 = (ImageView) convertView.findViewById(R.id.imgRank1Avt);

			holder.imgRank2 = (ImageView) convertView.findViewById(R.id.imgRank2Avt);
			
			holder.imgRank3 = (ImageView) convertView.findViewById(R.id.imgRank3Avt);
			
			convertView.setTag(holder);
			
		}
		else
		{
			holder = (MyHolder) convertView.getTag();
		}
		
		PhotoLoader.loadPhotoByWidth(mContext,data.getRank1().getAvartaUrl(), holder.imgRank1, withOfImage);
		PhotoLoader.loadPhotoByWidth(mContext,data.getRank2().getAvartaUrl(), holder.imgRank2, withOfImage);
		PhotoLoader.loadPhotoByWidth(mContext,data.getRank3().getAvartaUrl(), holder.imgRank3, withOfImage);
		
		holder.tvCategoryName.setText(data.getCategory().getCategoryName());
		holder.tvRank1Name.setText(data.getRank1().getName());
		holder.tvRank2Name.setText(data.getRank2().getName());
		holder.tvRank3Name.setText(data.getRank3().getName());
		
		return convertView;
	}

	class MyHolder 
	{
		
		TextView tvCategoryName;
		ImageView imgRank1,imgRank2,imgRank3;
		TextView tvRank1Name,tvRank2Name,tvRank3Name;
		
	}
	
}
